home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume16 / ecu3 / part02 < prev    next >
Encoding:
Internet Message Format  |  1991-01-06  |  50.0 KB

  1. From: wht@n4hgf.uucp (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v16i026:  ECU async comm package rev 3.0, Part02/35
  4. Message-ID: <1991Jan6.051710.27286@sparky.IMD.Sterling.COM>
  5. Date: 6 Jan 91 05:17:10 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 6b7d4abf a11b85ba d0ac993a 815e505c
  8.  
  9. Submitted-by: wht@n4hgf.uucp (Warren Tucker)
  10. Posting-number: Volume 16, Issue 26
  11. Archive-name: ecu3/part02
  12.  
  13. ---- Cut Here and feed the following to sh ----
  14. #!/bin/sh
  15. # This is part 02 of ecu3
  16. if touch 2>&1 | fgrep 'amc' > /dev/null
  17.  then TOUCH=touch
  18.  else TOUCH=true
  19. fi
  20. # ============= ecu.c ==============
  21. echo 'x - extracting ecu.c (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'ecu.c' &&
  23. X/*+-----------------------------------------------------------------------
  24. X    ecu.c - Extended Calling Unit/Call Utility/Call UNIX/whatever
  25. X    wht@n4hgf.Mt-Park.GA.US
  26. X
  27. X  Defined functions:
  28. X    main(argc,argv,envp)
  29. X    xmtr()
  30. X
  31. X------------------------------------------------------------------------*/
  32. X/*+:EDITS:*/
  33. X/*:11-30-1990-19:04-wht@n4hgf-new ttyinit parameter - see TTYINIT_... */
  34. X/*:11-28-1990-15:58-wht@n4hgf-add non-ansi terminal support */
  35. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  36. X
  37. X#define DECLARE_LINEVARS_PUBLIC
  38. X#include "ecu.h"
  39. X#include "esd.h"
  40. X#include "proc.h"
  41. X#include "ecukey.h"
  42. X#include "ecuxkey.h"
  43. X#include "ecuhangup.h"
  44. X#include "patchlevel.h"
  45. X#undef NULL
  46. X#include <sys/param.h>
  47. X
  48. Xchar *getenv();
  49. X
  50. Xextern char *makedate;            /* temporary make date */
  51. Xextern char *numeric_revision;    /* ecunumrev.c */
  52. Xextern char *revision_modifier; /* ecunumrev.c */
  53. Xextern ESD *icmd_prompt;
  54. Xextern char kbdeof;            /* current input EOF */
  55. Xextern char kbdeol2;        /* current secondary input EOL */
  56. Xextern char kbdeol;            /* current input EOL */
  57. Xextern char kbderase;        /* current input ERASE */
  58. Xextern char kbdintr;        /* current input INTR */
  59. Xextern char kbdkill;        /* current input KILL */
  60. Xextern char kbdquit;        /* current input QUIT */
  61. Xextern char kbd_is_7bit;    /* keyboard has parity */
  62. Xextern uint tcap_LINES;
  63. Xextern uint tcap_COLS;
  64. Xextern ulong colors_current;
  65. Xextern int there_is_hdb_on_this_machine;
  66. Xextern int tty_not_char_special;
  67. Xextern int tty_is_ansi;
  68. Xextern int tty_is_multiscreen;
  69. Xextern char lopen_err_str[];
  70. X
  71. Xchar curr_dir[258];        /* current working directory of process */
  72. Xchar hello_str[80];        /* msg printed upon BOJ */
  73. Xchar errmsg[128];
  74. Xchar modem_ctl_fname[128];
  75. Xchar initial_procedure[128] = "";
  76. Xint init_proc_argc = 0;
  77. Xchar *init_proc_argv[MAX_PARGV];
  78. Xint quiet = 0;            /* don't shut up is default */
  79. Xint rcvr_pid = -1;        /* pid for rcvr process (-1 == no proc active) */
  80. X    /* ... -2 == special flag for modem control/timed-read procedures */
  81. Xint xmtr_pid = 0;
  82. Xint quit_on_init_proc_fail = 0;
  83. Xint quit_on_init_proc_done = 0;
  84. Xint hz;
  85. Xstruct timeb starting_timeb;
  86. X
  87. X/*-----------------------*/
  88. Xint nice_value = 3;        /* go for hi priority */
  89. Xushort geteuid();
  90. Xushort getuid();
  91. Xushort euid;
  92. Xushort uid;
  93. X/*-----------------------*/
  94. X
  95. X/*+-----------------------------------------------------------------------
  96. X    xmtr() --  copy stdin to comm line
  97. X
  98. X  THE INITIAL PROCESS EXECUTES THIS PROCESS UNTIL PROGRAM TERMINATION
  99. X
  100. X  TTY input lines beginning with % have special significance
  101. X  (see ecuicmd.c)
  102. X------------------------------------------------------------------------*/
  103. Xint
  104. Xxmtr()
  105. X{
  106. Xuchar xmtr_char;
  107. Xuchar nlchar = NL;
  108. Xvoid xmtr_SIGINT_handler();
  109. X
  110. X    ttymode(1);
  111. X    xmtr_signals();
  112. X    while(1)
  113. X    {
  114. X/* bug somewhere ... may be SIGINT too rapidly causing SIG_IGN ????? */
  115. X        signal(SIGINT,xmtr_SIGINT_handler);    /* so make sure */
  116. X        xmtr_char = ttygetc(1);
  117. X
  118. X        if(xmtr_char & 0x80)
  119. X        {
  120. X            kbd_escape(xmtr_char);
  121. X            continue;
  122. X        }
  123. X
  124. X        lputc(xmtr_char);
  125. X        if(shm->Lfull_duplex == 0)        /* echo character if asked */
  126. X            write(TTYERR,&xmtr_char,1);
  127. X
  128. X        if(xmtr_char == CR)
  129. X        {
  130. X            if(shm->Ladd_nl_outgoing)
  131. X                lputc('\n');
  132. X            if(shm->Lfull_duplex == 0)
  133. X                write(TTYERR,&nlchar,1);
  134. X        }
  135. X    }        /* end of while we can read a character */
  136. X    return(HANGUP_XMTR_LOGIC_ERROR);    /* should not have gotten here */
  137. X
  138. X}    /* end of xmtr */
  139. X
  140. X/*+-------------------------------------------------------------------------
  141. X    main(argc,argv,envp)
  142. X
  143. X  main() program forks to create rcvr process; then main()
  144. X  becomes the xmtr process
  145. X------------------------------------------------------------------------*/
  146. Xmain(argc,argv,envp)
  147. Xint argc;
  148. Xchar **argv;
  149. Xchar **envp;
  150. X{
  151. Xint swchar;
  152. Xint itmp;
  153. Xulong colors_save;
  154. Xchar *get_ttyname();
  155. Xextern char *optarg;
  156. Xextern int optind;
  157. X
  158. X    ftime(&starting_timeb);    /* get startup time */
  159. X    xmtr_pid = getpid();
  160. X
  161. X#ifdef MALLOC_3X
  162. X    (void)mallopt(M_MXFAST,256+4);
  163. X    (void)mallopt(M_NLBLKS,64);
  164. X    (void)mallopt(M_GRAIN,sizeof(ESD) + 8);
  165. X#endif
  166. X
  167. X    if(!getenv("HZ"))
  168. X        hz = atoi(getenv("HZ"));
  169. X    else
  170. X        hz = HZ;
  171. X
  172. X    setbuf(stderr,NULL);
  173. X
  174. X/* get this off quick, cause we'll be busy for a little while on 286 */
  175. X    sprintf(hello_str,"ecu %s.%02d%s (pid %d) by wht@n4hgf",
  176. X        numeric_revision,PATCHLEVEL,revision_modifier,xmtr_pid);
  177. X    ff(se,"%s\n",hello_str);
  178. X
  179. X/* if we are root (as we should be on 286 versions), nice to very bad
  180. X   and set uid to real uid */
  181. X
  182. X    uid = getuid();
  183. X    euid = geteuid();
  184. X    if((euid == 0) || (uid == 0))    /* if root running or prog text ... */
  185. X    {                                /* ... sets to root, then grab gusto */
  186. X    int old_nice = nice(0) + 20;
  187. X        nice(-old_nice + nice_value);
  188. X        if(uid != euid)                    /* but if user not really root ... */
  189. X        {
  190. X            if(setuid(uid))            /* ... take away the privilege */
  191. X            {
  192. X                ff(se,"\r\n");
  193. X                perror("setuid");
  194. X                ff(se,"\r\n");
  195. X                exit(-1);
  196. X            }
  197. X        }
  198. X    }
  199. X
  200. X    shm_init();                /* open shared segment */
  201. X
  202. X    keyset_init();            /* intialize keyset */
  203. X
  204. X    make_ecu_subdir();        /* needs to be very early before lots of init */
  205. X
  206. X    xmtr_signals();            /* catch xmtr signals */
  207. X
  208. X    get_curr_dir(curr_dir,sizeof(curr_dir));
  209. X    cd_array_init();        /* read %cd directory list */
  210. X
  211. X    hdb_init();
  212. X
  213. X    var_init();                /* initialize procedure variables */
  214. X    poutput_init();            /* initialize procedure output */
  215. X
  216. X    icmd_prompt = make_esd(64);
  217. X    set_default_escape_prompt();
  218. X
  219. X/* init line variables */
  220. X    shm->Lline[0] = 0;                /* no line chosen yet */
  221. X    shm->Liofd = -1;                /* no line open now */
  222. X    shm->Lbaud = DEFAULT_BAUD_RATE;    /* see ecu.h */
  223. X    shm->Lparity = DEFAULT_PARITY;    /* see ecu.h */
  224. X    shm->Ltelno[0] = 0;                /* no telephone number for remote yet */
  225. X    shm->Llogical[0] = 0;            /* no logical name for remote yet */
  226. X    shm->Lrname[0] = 0;                /* no logical name for remote yet */
  227. X    shm->Ldescr[0] = 0;                /* no description for remote yet */
  228. X    shm->Lmodem_off_hook = 0;        /* assume modem on hook */
  229. X    shm->Ladd_nl_incoming = 0;        /* dont add nl to incoming cr */
  230. X    shm->Ladd_nl_outgoing = 0;        /* dont add nl to outgoing cr */
  231. X    shm->Lfull_duplex = 1;            /* assume full duplex */
  232. X    shm->Lmodem_already_init = 0;    /* modem has not been initialized */
  233. X    shm->Lxonxoff = IXON | IXOFF;    /* default to xon/xoff protocol */
  234. X    shm->xmtr_pid = getpid();
  235. X    shm->xmtr_ppid = getppid();
  236. X    shm->xmtr_pgrp = getpgrp(0);
  237. X    strcpy(shm->tty_name,get_ttyname());
  238. X    shm->shm_revision = SHM_REV;
  239. X    shm->ttyinit_param = TTYINIT_NORMAL;
  240. X
  241. X    while((swchar = getopt(argc,argv,"c:p:l:b:hfdDteoAN")) != -1)
  242. X    {
  243. X        switch(swchar)
  244. X        {
  245. X            case 'b':
  246. X                if(valid_baud_rate(shm->Lbaud = atoi(optarg)) < 0)
  247. X                {
  248. X                    ff(se,"invalid baud rate %u\n",shm->Lbaud);
  249. X                    usage();
  250. X                }
  251. X                break;
  252. X            case 'c':
  253. X                strcpy(modem_ctl_fname,optarg);
  254. X                break;
  255. X            case 'l':
  256. X                shm->Lline[0] = 0;
  257. X                if(strncmp(optarg,"/dev/tty",8))
  258. X                    strcpy(shm->Lline,"/dev/tty");
  259. X                strcat(shm->Lline,optarg);
  260. X                break;
  261. X            case 'p':
  262. X                strcpy(initial_procedure,optarg);
  263. X                break;
  264. X            case 'h': shm->Lfull_duplex = 0; break;
  265. X            case 'f': shm->Lfull_duplex = 1; break;
  266. X            case 'd': quit_on_init_proc_fail = 1; break;
  267. X            case 'D': quit_on_init_proc_done = 1; break;
  268. X            case 't': shm->Ladd_nl_incoming = 1;
  269. X                      shm->Ladd_nl_outgoing = 1; break;
  270. X            case 'e': shm->Lparity = 'e'; break;
  271. X            case 'o': shm->Lparity = 'o'; break;
  272. X            case 'A': shm->ttyinit_param = TTYINIT_FORCE_ANSI; break;
  273. X            case 'N': shm->ttyinit_param = TTYINIT_FORCE_NONANSI; break;
  274. X            case '?': usage();
  275. X        }
  276. X    }
  277. X
  278. X/* check a few options for validity */
  279. X    if(!initial_procedure[0] &&
  280. X        (quit_on_init_proc_done || quit_on_init_proc_fail))
  281. X    {
  282. X        ff(se,"no -D/-d without -p\n");
  283. X        usage();
  284. X    }
  285. X
  286. X    ttyinit(shm->ttyinit_param);    /* init console tty mode handler */
  287. X    ttymode(1);                        /* put user console in `raw' mode */
  288. X    tcap_clear_screen();
  289. X    ff(se,"%s\r\n",hello_str);
  290. X    if(kbd_is_7bit && !tty_not_char_special)
  291. X    {
  292. X        tcap_cursor(tcap_LINES - 3,0);
  293. X        ff(se,
  294. X    "No problem, but just to warn you, the keyboard has parity enabled\r\n");
  295. X        ring_bell();
  296. X        nap(1000L);
  297. X    }
  298. X
  299. X/* check out line */
  300. X    if(!shm->Lline[0])
  301. X    {
  302. X        if(!there_is_hdb_on_this_machine)
  303. X            strcpy(shm->Lline,"/dev/tty1a");
  304. X        else
  305. X        {
  306. X            choose_line(shm->Lbaud);
  307. X            if(!shm->Lline[0])
  308. X            {
  309. X                ff(se,"\r\n\n");
  310. X                tcap_stand_out();
  311. X                ff(se,"[no available Devices line at %u baud]",shm->Lbaud);
  312. X                tcap_stand_end();
  313. X                ff(se,"\r\n");
  314. X                strcpy(shm->Lline,"/dev/tty1a");
  315. X                nap(1000L);
  316. X            }
  317. X        }
  318. X    }
  319. X
  320. X/* either present startup screen or run initial procedure or both */
  321. X    if(initial_procedure[0])
  322. X    {
  323. X        init_proc_argv[0] = initial_procedure;
  324. X        init_proc_argc = 1;
  325. X        for(itmp = optind; itmp < argc; itmp++)
  326. X        {
  327. X            if(*argv[itmp] != '-')
  328. X            {
  329. X                if(init_proc_argc == MAX_PARGV)
  330. X                {
  331. X                    ff(se,"too many arguments to initial procedure\r\n");
  332. X                    hangup(HANGUP_USAGE);
  333. X                }
  334. X                init_proc_argv[init_proc_argc++] = argv[itmp];
  335. X            }
  336. X        }
  337. X
  338. X        if(tty_not_char_special)
  339. X            quit_on_init_proc_done = 1;
  340. X        else    /* rattle curses once - fixes quirk/bug I can't find */
  341. X        {
  342. X            windows_start();
  343. X            windows_end2();
  344. X            fflush(so);
  345. X        }
  346. X
  347. X        ttymode(2);
  348. X        if(do_proc(init_proc_argc,init_proc_argv))
  349. X        {
  350. X            if(quit_on_init_proc_fail || quit_on_init_proc_done)
  351. X                hangup(HANGUP_INIT_PROC_ERROR);
  352. X        }
  353. X        proc_file_reset();
  354. X        colors_save = colors_current;
  355. X        setcolor(colors_notify);
  356. X        fputs("[procedure finished]",se);
  357. X        setcolor(colors_save);
  358. X        ff(se,"\r\n");
  359. X        if(quit_on_init_proc_done)
  360. X            hangup(0);
  361. X        if(shm->Liofd < 0)
  362. X        {
  363. X            ttymode(1);    
  364. X            ff(se,"\r\n\n");
  365. X            tcap_stand_out();
  366. X            ff(se, "[no line attached by initial procedure]");
  367. X            tcap_stand_end();
  368. X            ff(se,"\r\n");
  369. X            if(quit_on_init_proc_fail)
  370. X                hangup(HANGUP_INIT_PROC_ERROR);
  371. X            tcap_stand_out();
  372. X            ff(se, "[press ESC to exit or SPACE for setup menu]");
  373. X            tcap_stand_end();
  374. X            itmp = ttygetc(0);
  375. X            ff(se,"\r\n");
  376. X            if(itmp == ESC)
  377. X                hangup(1);
  378. X            setup_screen((char *)0);
  379. X        }
  380. X        else
  381. X        {
  382. X            ttymode(1);
  383. X            start_rcvr_process(0);
  384. X        }
  385. X    }
  386. X    else        /* no initial procedure */
  387. X    {
  388. X        ttymode(1);    
  389. X        setup_screen((optind < argc) ? argv[optind] : (char *)0);
  390. X    }
  391. X
  392. X    /* enter xmtr operation */
  393. X    hangup(xmtr());
  394. X
  395. X    /*NOTREACHED*/
  396. X
  397. X}    /* end of main */
  398. X
  399. X/* end of ecu.c */
  400. X/* vi: set tabstop=4 shiftwidth=4: */
  401. SHAR_EOF
  402. $TOUCH -am 1226044490 'ecu.c' &&
  403. chmod 0644 ecu.c ||
  404. echo 'restore of ecu.c failed'
  405. Wc_c="`wc -c < 'ecu.c'`"
  406. test 9953 -eq "$Wc_c" ||
  407.     echo 'ecu.c: original size 9953, current size' "$Wc_c"
  408. # ============= ecuDCE.c ==============
  409. echo 'x - extracting ecuDCE.c (Text)'
  410. sed 's/^X//' << 'SHAR_EOF' > 'ecuDCE.c' &&
  411. X/* #define USE_S7 */
  412. X/*+-------------------------------------------------------------------------
  413. X    ecuDCE.c - ECU DCE dialing and management
  414. X    wht@n4hgf.Mt-Park.GA.US
  415. X
  416. X  Defined functions:
  417. X    DCE_hangup()
  418. X    DCE_autoanswer()
  419. X    DCE_dial()
  420. X    DCE_dial_pde(tpde)
  421. X    DCE_get_result(msec_to_wait)
  422. X    DCE_get_sreg_value(regnum)
  423. X    DCE_modem_init()
  424. X    DCE_now_on_hook()
  425. X    DCE_read_modem_init()
  426. X    DCE_redial(arg,argc)
  427. X    DCE_report_iv_set(varnum)
  428. X    DCE_send_cmd(cmd)
  429. X    DCE_set_sreg(regnum,value)
  430. X    ck_for_interrupt()
  431. X    process_modem_init(str)
  432. X    show_modem_init_error(erc,iesd)
  433. X
  434. X--------------------------------------------------------------------------*/
  435. X/*+:EDITS:*/
  436. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  437. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  438. X
  439. X#include "ecu.h"
  440. X#include "ecukey.h"
  441. X#include "esd.h"
  442. X#include "var.h"
  443. X#include "ecupde.h"
  444. X#include "ecuerror.h"
  445. X#include "relop.h"
  446. X
  447. Xlong time();
  448. X
  449. Xchar *make_char_graphic();
  450. Xvoid DCE_hangup();
  451. X
  452. Xextern int rcvr_pid;
  453. Xextern int interrupt;
  454. Xextern int proc_interrupt;
  455. Xextern int proctrace;
  456. Xextern ulong colors_current;
  457. Xextern char kbdintr;
  458. X
  459. Xint mi_line;
  460. Xchar mi_name[64];
  461. X
  462. X#define MI_MAX_LEN 65
  463. Xchar Lmodem_init[MI_MAX_LEN] = "";        /* modem init string w/o trailing CR */
  464. Xchar Lmodem_dial[MI_MAX_LEN] = "";        /* modem dialing prefix */
  465. Xchar Lmodem_autoans[MI_MAX_LEN] = "";    /* modem autoanswer */
  466. X
  467. Xchar *interrupted_string = "!Interrupted";
  468. X
  469. X/*+-------------------------------------------------------------------------
  470. X    ck_for_interrupt()
  471. X--------------------------------------------------------------------------*/
  472. Xck_for_interrupt()
  473. X{
  474. Xuint key;
  475. X
  476. X    while(rdchk(0))
  477. X    {
  478. X        if((uchar)(key = ttygetc(1)) == (uchar)kbdintr)
  479. X        {
  480. X            interrupt = 1;
  481. X            return(1);
  482. X        }
  483. X    }
  484. X    return(0);
  485. X}    /* end of ck_for_interrupt */
  486. X
  487. X/*+-------------------------------------------------------------------------
  488. X    show_modem_init_error(erc,iesd)
  489. X--------------------------------------------------------------------------*/
  490. Xvoid
  491. Xshow_modem_init_error(erc,iesd)
  492. Xint erc;
  493. XESD *iesd;
  494. X{
  495. Xregister itmp;
  496. X
  497. X    pputs(mi_name);
  498. X    pprintf(" line %d: ",mi_line);
  499. X    proc_error(erc);
  500. X    pputs(iesd->pb);
  501. X    pputc(NL);
  502. X    itmp = iesd->old_index;
  503. X    while(itmp--)
  504. X        pputc(' ');
  505. X    pputs("^\n\n");
  506. X
  507. X}    /* end of show_modem_init_error */
  508. X
  509. X/*+-----------------------------------------------------------------------
  510. X    process_modem_init(str)
  511. X
  512. Xsample /usr/lib/ecu/tty??.mi lines:
  513. Xinit_9600:ATS11=47X4S0=0S7=30\Q0\X0\N0
  514. Xinit_>2400:ATS11=47X4S0=0S7=30\Q0\X0\N0
  515. Xinit_<=2400:ATS11=47X4S0=0S7=30\Q1\X1\N3
  516. XATDT
  517. X
  518. Xreturn 0 if entire list read, else 1 if error (error msg in errmsg)
  519. X------------------------------------------------------------------------*/
  520. Xvoid
  521. Xprocess_modem_init(str)
  522. Xchar *str;
  523. X{
  524. X#define MI_INIT        1
  525. X#define MI_DIAL        2
  526. X#define MI_AUTOANS    3
  527. Xint erc;
  528. XESD sesd;
  529. Xchar typestr[32];
  530. Xint relop;
  531. Xint truth = 0;
  532. Xint type;
  533. Xlong test_baud;
  534. X
  535. X    sesd.pb = str;
  536. X    sesd.cb = strlen(str);
  537. X    sesd.maxcb = strlen(str);
  538. X    sesd.index = 0;
  539. X    sesd.old_index = 0;
  540. X
  541. X    if(get_alpha_zstr(&sesd,typestr,sizeof(typestr)))
  542. X    {
  543. X        erc = eSyntaxError;
  544. X        goto SHOW_ERROR;
  545. X        return;
  546. X    }
  547. X    if(ulindex(typestr,"init_") == 0)
  548. X        type = MI_INIT;
  549. X    else if(ulindex(typestr,"dial_") == 0)
  550. X        type = MI_DIAL;
  551. X    else if(!strcmpi(typestr,"autoanswer"))
  552. X        type = MI_AUTOANS;
  553. X    else
  554. X    {
  555. X        erc = eSyntaxError;
  556. X        goto SHOW_ERROR;
  557. X    }
  558. X
  559. X/* test for default ... if none, check baud rate */
  560. X    if(type == MI_AUTOANS)
  561. X        truth = 1;
  562. X    else if(ulindex(typestr,"_default") > 0)
  563. X    {
  564. X        truth = !( ((type == MI_INIT) && Lmodem_init[0]) ||
  565. X            ((type == MI_DIAL) && Lmodem_dial[0]));
  566. X    }
  567. X    else
  568. X    {
  569. X        /* get optional operator */
  570. X        if(get_relop(&sesd,&relop))
  571. X            relop = OP_EQ;
  572. X        if(erc = gint_constant(&sesd,&test_baud))
  573. X            goto SHOW_ERROR;
  574. X        truth = test_truth_int((long)shm->Lbaud,relop,test_baud);
  575. X    }
  576. X
  577. X/* if no match, skip this one */
  578. X    if(!truth)
  579. X        return;
  580. X
  581. X/* skip over colon */
  582. X    if(erc = skip_colon(&sesd))
  583. X        goto SHOW_ERROR;
  584. X
  585. X/* make sure init or dial string not empty or too long */
  586. X    if((erc = skip_cmd_break(&sesd)) && (type != MI_AUTOANS))
  587. X        goto SHOW_ERROR;
  588. X
  589. X    if((sesd.cb - sesd.index) > (MI_MAX_LEN - 1))
  590. X    {
  591. X        erc = eBufferTooSmall;
  592. X        goto SHOW_ERROR;
  593. X    }
  594. X
  595. X    erc = eDuplicateMatch;        /* in case of show error in switch */
  596. X    switch(type)
  597. X    {
  598. X        case MI_INIT:
  599. X            if(Lmodem_init[0])
  600. X                goto SHOW_ERROR;
  601. X            strcpy(Lmodem_init,sesd.pb + sesd.index);
  602. X            break;
  603. X
  604. X        case MI_DIAL:
  605. X            if(Lmodem_dial[0])
  606. X                goto SHOW_ERROR;
  607. X            strcpy(Lmodem_dial,sesd.pb + sesd.index);
  608. X            break;
  609. X
  610. X        case MI_AUTOANS:
  611. X            if(Lmodem_autoans[0])
  612. X                goto SHOW_ERROR;
  613. X            if(!sesd.cb)
  614. X                strcpy(Lmodem_autoans,"!null!");
  615. X            else
  616. X                strcpy(Lmodem_autoans,sesd.pb + sesd.index);
  617. X            break;
  618. X            
  619. X    }
  620. X    return;        /* <<<<====== done */
  621. X
  622. XSHOW_ERROR:
  623. X    show_modem_init_error(erc,&sesd);
  624. X
  625. X}    /* end of process_modem_init */
  626. X
  627. X/*+-----------------------------------------------------------------------
  628. X    DCE_read_modem_init()
  629. X0123456789
  630. X/dev/ttyxx
  631. X------------------------------------------------------------------------*/
  632. Xvoid
  633. XDCE_read_modem_init()
  634. X{
  635. Xchar *cptr;
  636. Xregister FILE *fp_modem;
  637. Xchar *skip_ld_break();
  638. Xchar buffer[128];
  639. X
  640. X/* zap init information */
  641. X    Lmodem_init[0] = 0;
  642. X    Lmodem_dial[0] = 0;
  643. X
  644. X/* build filename */
  645. X    sprintf(mi_name,"%s/%s.mi",ECULIBDIR,shm->Lline + 5);
  646. X
  647. X/* read modem initialization */
  648. X    if(!(fp_modem = fopen(mi_name,"r")))
  649. X        pperror(mi_name);
  650. X    else
  651. X    {
  652. X        mi_line = 0;
  653. X        while((!Lmodem_init[0] || !Lmodem_dial[0]) &&
  654. X            fgets(buffer,sizeof(buffer),fp_modem))
  655. X        {
  656. X            mi_line++;
  657. X            buffer[strlen(buffer) - 1] = 0;
  658. X            cptr = skip_ld_break(buffer);
  659. X            /* skip comments and null lines */
  660. X            if(!strlen(cptr) || (*cptr == '#'))
  661. X                continue;
  662. X            process_modem_init(cptr);
  663. X        }
  664. X        fclose(fp_modem);
  665. X    }
  666. X
  667. X/* default */
  668. X    if(!Lmodem_init[0])
  669. X    {
  670. X        strcpy(Lmodem_init,"ATE1Q0V1");
  671. X        pputs("modem init string not found (using default '");
  672. X        pputs(Lmodem_init);
  673. X        pputs("')\n");
  674. X    }
  675. X    if(!Lmodem_dial[0])
  676. X    {
  677. X        strcpy(Lmodem_dial,"ATDT");
  678. X        pputs("modem dial string not found (using default '");
  679. X        pputs(Lmodem_dial);
  680. X        pputs("')\n");
  681. X    }
  682. X
  683. X    if(!Lmodem_autoans[0])
  684. X    {
  685. X        strcpy(Lmodem_autoans,"ATQ1S0=1");
  686. X#ifdef INUSE
  687. X        pputs("modem autoanswer string not found (using default '");
  688. X        pputs(Lmodem_autoans);
  689. X        pputs("')\n");
  690. X#endif
  691. X    }
  692. X    else if(!strcmp(Lmodem_autoans,"!null!"))
  693. X        Lmodem_autoans[0] = 0;
  694. X
  695. X    if(proctrace > 1)
  696. X    {
  697. X        pprintf("init:       '%s'\n",Lmodem_init);
  698. X        pprintf("dial:       '%s'\n",Lmodem_dial);
  699. X        pprintf("autoanswer: '%s'\n",Lmodem_autoans);
  700. X    }
  701. X}    /* end of DCE_read_modem_init */
  702. X
  703. X/*+-------------------------------------------------------------------------
  704. X    DCE_get_result(msec_to_wait)
  705. Xreturn pointer to static buf containing result code
  706. X--------------------------------------------------------------------------*/
  707. Xchar *
  708. XDCE_get_result(msec_to_wait)
  709. Xlong msec_to_wait;
  710. X{
  711. Xstatic char s32[32];
  712. XLRWT    lr;
  713. X
  714. X    interrupt = 0;
  715. X    s32[0] = 0;
  716. X    lr.to1 = msec_to_wait;
  717. X    lr.to2 = 200L;
  718. X    lr.raw_flag = 0x80; /* allow interrupts */
  719. X    lr.buffer = s32;
  720. X    lr.bufsize = sizeof(s32);
  721. X    lr.delim = (char *)0;
  722. X    lr.echo = 0;
  723. X    lgets_timeout(&lr);
  724. X    return(lr.buffer);
  725. X
  726. X/* reset any interrupt indication since we look at string */
  727. X    interrupt = 0;
  728. X
  729. X}    /* end of DCE_get_result */
  730. X
  731. X/*+-------------------------------------------------------------------------
  732. X    DCE_modem_init()
  733. X--------------------------------------------------------------------------*/
  734. XDCE_modem_init()
  735. X{
  736. Xregister itmp;
  737. Xint retries = 0;
  738. Xchar *cmd;
  739. Xchar *cptr;
  740. Xint old_ttymode = get_ttymode();
  741. X
  742. X    if(shm->Lmodem_already_init)
  743. X        return(0);
  744. X
  745. X    interrupt = 0;
  746. X    DCE_read_modem_init();
  747. X
  748. X    lputs_paced(0,"\b\b\b\b\b\b\b\b\b\r");
  749. X    nap(200L);
  750. X    lflush(0);
  751. X
  752. X    while(!shm->Lmodem_already_init)
  753. X    {
  754. XINIT_LOOP:
  755. X        if(retries > 3)
  756. X            goto ERROR_RETURN;
  757. X
  758. X        if(interrupt)
  759. X            goto ERROR_RETURN;
  760. X
  761. X        if(retries)
  762. X        {
  763. X            ltoggle_dtr();
  764. X            lputs_paced(0,"AT\r");
  765. X            nap(400L);
  766. X            lputs_paced(0,"ATQ0V1E1\r");
  767. X            nap(400L);
  768. X        }
  769. X
  770. X        lflush(0);
  771. X        cmd = Lmodem_init;
  772. X        itmp = 0;
  773. X#ifdef NEUROTIC
  774. X        while(*cmd)
  775. X        {
  776. X            lputc_paced(0,*cmd++);
  777. X            if(++itmp < 2)
  778. X                nap(40L);
  779. X            if((itmp = lgetc_timeout(500L)) < 0)
  780. X            {
  781. X                if(interrupt)
  782. X                    goto ERROR_RETURN;
  783. X                retries++;
  784. X                goto INIT_LOOP;
  785. X            }
  786. X            pputc(itmp);
  787. X        }
  788. X#else
  789. X        lputs(cmd);
  790. X        pputs(cmd);
  791. X#endif
  792. X
  793. X        pputc(NL);
  794. X        lputc_paced(0,CR);
  795. X
  796. X        itmp = 0;
  797. X        while(itmp != CR)
  798. X        {
  799. X            if((itmp = lgetc_timeout(500L)) < 0)
  800. X            {
  801. X                if(interrupt)
  802. X                    goto ERROR_RETURN;
  803. X                pputs("missed expected carriage return\n");
  804. X                retries++;
  805. X                goto INIT_LOOP;
  806. X            }
  807. X        }
  808. X
  809. X        if(strcmp(cptr = DCE_get_result(1200L),"OK"))
  810. X        {
  811. X            if(!strcmp(cptr,interrupted_string))
  812. X            {
  813. X                interrupt = 1;
  814. X                goto ERROR_RETURN;
  815. X            }
  816. X            pprintf("unexpected result: '%s'\n",cptr);
  817. X            retries++;
  818. X            continue;
  819. X        }
  820. X        shm->Lmodem_already_init = 1;
  821. X    }
  822. X
  823. X    ttymode(old_ttymode);
  824. X    return(0);
  825. X
  826. XERROR_RETURN:
  827. X    ttymode(old_ttymode);
  828. X    return(-1);
  829. X
  830. X}    /* end of DCE_modem_init */
  831. X
  832. X/*+-------------------------------------------------------------------------
  833. X    DCE_send_cmd(cmd)
  834. X--------------------------------------------------------------------------*/
  835. Xint
  836. XDCE_send_cmd(cmd)
  837. Xregister char *cmd;
  838. X{
  839. Xregister itmp;
  840. X
  841. X    DCE_modem_init();
  842. X    nap(600L);
  843. X
  844. X    lflush(0);
  845. X#ifdef NEUROTIC
  846. X    while(*cmd)
  847. X    {
  848. X        lputc_paced(20,*cmd++);
  849. X        if(++char_count < 2)
  850. X            nap(40L);
  851. X        if((itmp = lgetc_timeout(500L)) < 0)
  852. X            return(-1);
  853. X        pputc(itmp);
  854. X    }
  855. X#else
  856. X    lputs(cmd);
  857. X    pputs(cmd);
  858. X#endif
  859. X    pputc(NL);
  860. X    lputc_paced(20,CR);
  861. X    itmp = 0;
  862. X    if(ck_for_interrupt())
  863. X        return(-1);
  864. X    while(itmp != CR)
  865. X    {
  866. X        if((itmp = lgetc_timeout(500L)) < 0)
  867. X        {
  868. X            pputs("missed expected carriage return\n");
  869. X            return(-1);
  870. X        }
  871. X        if(ck_for_interrupt())
  872. X            return(-1);
  873. X    }
  874. X    return(0);
  875. X
  876. X}    /* end of DCE_send_cmd */
  877. X
  878. X/*+-------------------------------------------------------------------------
  879. X    DCE_report_iv_set(varnum)
  880. X--------------------------------------------------------------------------*/
  881. Xvoid
  882. XDCE_report_iv_set(varnum)
  883. Xint varnum;
  884. X{
  885. X
  886. X    if(proctrace)
  887. X        pprintf("modem handler set $i%02d = %ld\n",varnum,iv[varnum]);
  888. X}    /* end of DCE_report_iv_set */
  889. X
  890. X/*+-----------------------------------------------------------------------
  891. X    DCE_dial() - dial a remote or connect
  892. X
  893. X  returns 0 on success (CONNECT),
  894. X          eConnectFailed if failure
  895. X          eCONINT on interrupt
  896. X
  897. X  sets I0 to 0==connect,
  898. X             1==failed to connect,
  899. X             2==interrupted
  900. X             3==modem error
  901. X  sets S0 to modem result code or uucp status code string
  902. X
  903. X  This function has gotten quite NASTY and needs rewriting!
  904. X------------------------------------------------------------------------*/
  905. Xint
  906. XDCE_dial()
  907. X{
  908. Xchar s128[128];
  909. Xint rcvr_was_alive = (rcvr_pid > 0) || (rcvr_pid == -2);
  910. Xint itmp;
  911. Xint erc;
  912. Xint s7;
  913. Xchar *result = "";
  914. Xulong colors_at_entry = colors_current;
  915. Xchar s64[64];
  916. X#ifdef WHT    /* hack for immediate need ... make a real feature later */
  917. Xchar *cptr;
  918. XFILE *fp;
  919. Xchar credit_file[128];
  920. X#endif
  921. Xextern char kbdintr;        /* current input INTR */
  922. X
  923. X    if(rcvr_was_alive && (rcvr_pid != -2))
  924. X    {
  925. X        kill_rcvr_process(SIGUSR1);
  926. X        nap(500L);
  927. X    }
  928. X
  929. X    if(shm->Ldescr[0])
  930. X    {
  931. X        setcolor(colors_success);
  932. X        get_tod(1,s64);
  933. X        pprintf("%s %s on %s at %u baud (%s)\n",
  934. X            (shm->Ltelno[0]) ? "Dialing" : "Connecting to",
  935. X            shm->Ldescr,shm->Lline,shm->Lbaud,s64);
  936. X    }
  937. X
  938. X    setcolor(colors_alert);
  939. X    shm->Lmodem_off_hook = 0;
  940. X
  941. X    if(!shm->Ltelno[0])    /* if no phone number, direct connect */
  942. X    {
  943. X        sprintf(s128,"CONNECT %u",shm->Lbaud);
  944. X        result = s128;
  945. X        iv[0] = 0;
  946. X        erc = 0;
  947. X        goto START_RCVR_PROCESS;
  948. X    }
  949. X     else
  950. X    {
  951. X        itmp = hdb_dial(&result);
  952. X        lreset_ksr();    /* dialer may have changed parity */
  953. X        switch(itmp)
  954. X        {
  955. X            case 0:        /* success */
  956. X                goto CONNECTED;
  957. X            case 1:        /* failure -- iv[0] set by hdb_dial */
  958. X                DCE_report_iv_set(0);
  959. X                erc = eConnectFailed;
  960. X                goto START_RCVR_PROCESS;
  961. X            case 2:        /* interrupted -- iv[0] set by hdb_dial */
  962. X                DCE_report_iv_set(0);
  963. X                erc = eCONINT;
  964. X                goto START_RCVR_PROCESS;
  965. X            case 3:        /* modem error */
  966. X                setcolor(colors_error);
  967. X                pprintf("%s\n",result);
  968. X                goto CANNOT_TALK_TO_MODEM;
  969. X            case 4:        /* try local */
  970. X                break;
  971. X        }
  972. X
  973. X        DCE_modem_init();
  974. X
  975. X#if defined(USE_S7)
  976. X        if((s7 = DCE_get_sreg_value(7)) < 0)
  977. X            s7 = 30;
  978. X#else
  979. X        s7 = 30;
  980. X#endif
  981. X
  982. X        /* build and send dial command */
  983. X        strcpy(s128,Lmodem_dial);
  984. X        strcat(s128,shm->Ltelno);
  985. X#ifdef WHT    /* hack for immediate need ... make a real feature later */
  986. X        if(*(cptr = s128 + strlen(s128) - 1) == '$')
  987. X        {
  988. X            *cptr = 0;
  989. X            get_home_dir(credit_file);
  990. X            strcat(credit_file,"/.ecu/.credit");
  991. X            if(fp = fopen(credit_file,"r"))
  992. X            {
  993. X                *cptr++ = ',';
  994. X                *cptr++ = ',';
  995. X                *cptr++ = ',';
  996. X                *cptr++ = ',';
  997. X                *cptr = 0;
  998. X                fgets(cptr,30,fp);
  999. X                fclose(fp);
  1000. X            }
  1001. X            if(!fp || !(*cptr))
  1002. X            {
  1003. X                result = "credit card error";
  1004. X                goto CONNECT_FAILED;
  1005. X            }
  1006. X            *(cptr + strlen(cptr) - 1) = 0; /* kill NL */
  1007. X        }
  1008. X#endif /* WHT */
  1009. X
  1010. X        if(ck_for_interrupt())
  1011. X            goto SEND_CMD_ERROR;
  1012. X
  1013. X        if(DCE_send_cmd(s128))
  1014. X            goto SEND_CMD_ERROR;
  1015. X
  1016. X        /* some modems (ahem, the Hayes 2400) do not accurately honor S7
  1017. X        so our timer is twice sreg 7 */
  1018. X         pprintf("Type %s to abort ... ",make_char_graphic(kbdintr,1));
  1019. X        lflush(0);
  1020. X        result = DCE_get_result(s7 * 2 * 1000L);
  1021. X
  1022. X        if(!strcmp(result,interrupted_string))
  1023. X        {
  1024. X            setcolor(colors_error);
  1025. X            pprintf("%s\n",result);
  1026. X            lputc(0);                /* make modem go on hook */
  1027. X            nap(40L);
  1028. X            lputc(0);
  1029. X            interrupt = 0;
  1030. X            DCE_get_result(2000L);    /* wait for NO CARRIER */
  1031. X            erc = eCONINT;
  1032. X            iv[0] = 2;
  1033. X            DCE_report_iv_set(0);
  1034. X            goto START_RCVR_PROCESS;
  1035. X        }
  1036. X        if(!strncmp(result,"CONNECT",7))
  1037. X        {
  1038. X            if(strlen(result) > 7)
  1039. X            {
  1040. X                if(shm->Lbaud != (unsigned)atoi(result + 7))
  1041. X                {
  1042. X                    setcolor(colors_error);
  1043. X                    pprintf("%s (incorrect rate)\n",result);
  1044. X                    iv[0] = 2;
  1045. X                    DCE_report_iv_set(0);
  1046. X                    goto START_RCVR_PROCESS;
  1047. X                }
  1048. X            }
  1049. XCONNECTED:
  1050. X            setcolor(colors_success);
  1051. X            pprintf("%s\n",result);
  1052. X            sprintf(s128,"CONNECT %s (%s) %u baud",
  1053. X                shm->Llogical,shm->Ltelno,shm->Lbaud);
  1054. X            strcpy(shm->Lrname,shm->Llogical);
  1055. X            ecu_log_event(getpid(),s128);
  1056. X            if(isalpha(shm->Llogical[0]))
  1057. X                if(keyset_read(shm->Llogical) != 0)
  1058. X                    keyset_init();
  1059. X            shmx_connect();
  1060. X            shm->xmit_chars_this_connect = 0L;
  1061. X            shm->Loff_hook_time = time((long *)0);
  1062. X            iv[0] = 0;
  1063. X            DCE_report_iv_set(0);
  1064. X            erc = 0;
  1065. X            shm->Lmodem_off_hook = 1;
  1066. X            goto START_RCVR_PROCESS;
  1067. X        }
  1068. X        setcolor(colors_error);
  1069. XCONNECT_FAILED:
  1070. X        pprintf("%s\n",result);
  1071. X        iv[0] = 1;
  1072. X        DCE_report_iv_set(0);
  1073. X        erc = eConnectFailed;
  1074. X        goto START_RCVR_PROCESS;
  1075. X    }
  1076. X
  1077. X    shm->Lmodem_off_hook = 1;
  1078. X
  1079. XSTART_RCVR_PROCESS:    ;
  1080. X    setcolor(colors_at_entry);
  1081. X    strcpy(sv[0]->pb,result);
  1082. X    sv[0]->cb = strlen(result);
  1083. X    if(rcvr_was_alive)
  1084. X        start_rcvr_process(1);
  1085. X    return(erc);
  1086. X
  1087. XSEND_CMD_ERROR: ;
  1088. X    if(interrupt || proc_interrupt)
  1089. X    {
  1090. X        result = interrupted_string;
  1091. X        iv[0] = 2;
  1092. X        DCE_report_iv_set(0);
  1093. X        erc = eCONINT;
  1094. X    }
  1095. X    else
  1096. X    {
  1097. XCANNOT_TALK_TO_MODEM:
  1098. X        setcolor(colors_error);
  1099. X        pprintf("Cannot talk to modem\n");
  1100. X        result = "!Modem Error";
  1101. X        iv[0] = 3;
  1102. X        DCE_report_iv_set(0);
  1103. X        erc = eConnectFailed;
  1104. X    }
  1105. X    goto START_RCVR_PROCESS;
  1106. X
  1107. X}    /* end of DCE_dial */
  1108. X
  1109. X/*+-------------------------------------------------------------------------
  1110. X    DCE_dial_pde(tpde) - curses access dial command
  1111. X--------------------------------------------------------------------------*/
  1112. Xint
  1113. XDCE_dial_pde(tpde)
  1114. Xregister PDE *tpde;
  1115. X{
  1116. X    copy_pde_to_lvar(tpde);
  1117. X    return(DCE_dial());
  1118. X}    /* end of DCE_dial_pde */
  1119. X
  1120. X/*+-------------------------------------------------------------------------
  1121. X    DCE_redial(arg,argc)
  1122. X--------------------------------------------------------------------------*/
  1123. XDCE_redial(arg,argc)
  1124. Xchar **arg;
  1125. Xint argc;
  1126. X{
  1127. Xint erc = 0;
  1128. Xint delay = 60;
  1129. Xint retries = 10;
  1130. Xint nap_decisec;
  1131. Xint ans;
  1132. X
  1133. X    if(shm->Ltelno[0] == 0)
  1134. X    {
  1135. X        pprintf("   no previous number\n");
  1136. X        return(-1);
  1137. X    }
  1138. X
  1139. X    if((argc > 1) && ((retries = atoi(arg[1])) == 0))
  1140. X    {
  1141. X        pprintf("  invalid retry count\n");
  1142. X        return(-1);
  1143. X    }
  1144. X
  1145. X    if((argc > 2) && ((delay = atoi(arg[2])) == 0))
  1146. X    {
  1147. X        pprintf("  invalid delay\n");
  1148. X        return(-1);
  1149. X    }
  1150. X
  1151. X    if(delay < 15)        /* try to be nice to telcos */
  1152. X        delay = 15;        /* (they are our friends :-) */
  1153. X
  1154. X    pprintf("  for %d retries, pause between: %d secs\n",
  1155. X                retries,delay);
  1156. X
  1157. X    kill_rcvr_process(SIGUSR1);        /* kill rcvr process */
  1158. X
  1159. X    DCE_hangup();
  1160. X    while(retries--)
  1161. X    {
  1162. X    register itmp;
  1163. X
  1164. X#ifdef AUTO_DIAL_PROC
  1165. X        if(!isdigit(shm->Llogical[0]) && find_procedure(shm->Llogical))
  1166. X        {
  1167. X        char *pargv[2];
  1168. X        ulong colors_at_entry = colors_current;
  1169. X            pargv[0] = shm->Llogical;
  1170. X            pargv[1] = "!REDIAL;";
  1171. X            ttymode(2);
  1172. X            erc = do_proc(2,pargv);
  1173. X            interrupt = 0;
  1174. X            proc_file_reset();
  1175. X            ttymode(1);
  1176. X            setcolor(colors_notify);
  1177. X            ff(se,"[procedure finished]");
  1178. X            setcolor(colors_at_entry);
  1179. X            ff(se,"\r\n");
  1180. X            if(!erc)
  1181. X            {
  1182. X                start_rcvr_process(0);
  1183. X                return(0);
  1184. X            }
  1185. X            if(erc >= e_FATAL)
  1186. X                break;
  1187. X        }
  1188. X        else if(!(erc = DCE_dial()))
  1189. X        {
  1190. X#ifdef WHT
  1191. X            bell_notify(XBELL_C);
  1192. X#endif
  1193. X            start_rcvr_process(1);
  1194. X            return(0);
  1195. X        }
  1196. X#else
  1197. X        if(!(erc = DCE_dial()))
  1198. X        {
  1199. X#ifdef WHT
  1200. X            bell_notify(XBELL_C);
  1201. X#endif
  1202. X            start_rcvr_process(1);
  1203. X            return(0);
  1204. X        }
  1205. X#endif
  1206. X
  1207. X        if((retries == 0) || (erc >= e_FATAL))
  1208. X            break;
  1209. X
  1210. X        pprintf("%d %s left ... ",retries,(retries == 1) ? "retry" : "retries");
  1211. X        nap_decisec = delay * 10;
  1212. X        ff(se,"waiting %d seconds ... 'c' to cycle, %s to abort\r\n",
  1213. X            delay,(kbdintr == DEL) ?"DEL":make_char_graphic(kbdintr,0));
  1214. X        while(nap_decisec--)
  1215. X        {
  1216. X            nap(100L);
  1217. X            while(rdchk(0))
  1218. X            {
  1219. X                ans = to_lower(ttygetc(1));
  1220. X                if(ans == 'c')
  1221. X                    goto CONTINUE_CYCLE;
  1222. X                else if(ans == kbdintr)
  1223. X                    goto ABORT_CYCLE;
  1224. X                else
  1225. X                    ring_bell();
  1226. X            }
  1227. X            if(interrupt)
  1228. X                goto ABORT_CYCLE;
  1229. X        }
  1230. XCONTINUE_CYCLE:
  1231. X        ;
  1232. X    }
  1233. X
  1234. XERROR_RETURN:
  1235. X    start_rcvr_process(1);
  1236. X    return(-1);
  1237. X
  1238. XABORT_CYCLE:
  1239. X    ff(se,"redial ABORTED\r\n");
  1240. X    interrupt = 0;
  1241. X    goto ERROR_RETURN;
  1242. X}    /* end of DCE_redial */
  1243. X
  1244. X/*+-------------------------------------------------------------------------
  1245. X    DCE_now_on_hook()
  1246. X--------------------------------------------------------------------------*/
  1247. Xvoid
  1248. XDCE_now_on_hook()
  1249. X{
  1250. Xchar s128[128];
  1251. Xlong connect_secs;
  1252. Xlong time();
  1253. Xchar *get_elapsed_time();
  1254. X
  1255. X    if(shm->Lmodem_off_hook)
  1256. X    {
  1257. X        connect_secs = time((long *)0) - shm->Loff_hook_time;
  1258. X        sprintf(s128,"DISCONNECT %s (%s) %ld %s",
  1259. X            shm->Llogical,shm->Ltelno,connect_secs,
  1260. X            get_elapsed_time(connect_secs));
  1261. X        ecu_log_event(getpid(),s128);
  1262. X        shm->Lmodem_off_hook = 0;
  1263. X    }
  1264. X    shm->Lrname[0] = 0;
  1265. X
  1266. X}    /* end of DCE_now_on_hook */
  1267. X
  1268. X/*+-------------------------------------------------------------------------
  1269. X    DCE_hangup()
  1270. X--------------------------------------------------------------------------*/
  1271. Xvoid
  1272. XDCE_hangup()
  1273. X{
  1274. Xint rcvr_was_alive = 0;
  1275. X
  1276. X    if(rcvr_pid > 0)
  1277. X    {
  1278. X        rcvr_was_alive = 1;
  1279. X        kill_rcvr_process(SIGUSR1);
  1280. X        nap(500L);
  1281. X    }
  1282. X
  1283. X    ltoggle_dtr();
  1284. X    DCE_now_on_hook();
  1285. X    set_default_escape_prompt();
  1286. X
  1287. X    if(rcvr_was_alive)
  1288. X        start_rcvr_process(0);
  1289. X
  1290. X}    /* end of DCE_hangup */
  1291. X
  1292. X/*+-------------------------------------------------------------------------
  1293. X    DCE_get_sreg_value(regnum)
  1294. X assumes rcvr process has been killed
  1295. X--------------------------------------------------------------------------*/
  1296. Xint
  1297. XDCE_get_sreg_value(regnum)
  1298. Xint regnum;
  1299. X{
  1300. Xchar s128[128];
  1301. XLRWT    lr;
  1302. X
  1303. X    sprintf(s128,"ATS%d?",regnum);
  1304. X    DCE_send_cmd(s128);
  1305. X    lflush(0);
  1306. X    lr.to1 = 2000L;
  1307. X    lr.to2 = 140L;
  1308. X    lr.raw_flag = 0;
  1309. X    lr.buffer = s128;
  1310. X    lr.bufsize = sizeof(s128);
  1311. X    lr.delim = (char *)0;
  1312. X    lr.echo = 0;
  1313. X    lgets_timeout(&lr);
  1314. X    if(lr.count != 3)
  1315. X        return(-1);
  1316. X    return(atoi(s128));
  1317. X
  1318. X}    /* end of DCE_get_sreg_value */
  1319. X
  1320. X/*+-------------------------------------------------------------------------
  1321. X    DCE_set_sreg(regnum,value)
  1322. X assumes rcvr process has been killed
  1323. X returns 0 if no error (reads back value set),
  1324. X else -1 and error message has been printed
  1325. X--------------------------------------------------------------------------*/
  1326. Xint
  1327. XDCE_set_sreg(regnum,value)
  1328. Xint regnum;
  1329. Xint value;
  1330. X{
  1331. Xchar s128[128];
  1332. Xint value2;
  1333. XLRWT    lr;
  1334. X
  1335. X    sprintf(s128,"ATS%d=%d",regnum,value);
  1336. X    DCE_send_cmd(s128);
  1337. X    lflush(0);
  1338. X    lr.to1 = 2000L;
  1339. X    lr.to2 = 140L;
  1340. X    lr.raw_flag = 0;
  1341. X    lr.buffer = s128;
  1342. X    lr.bufsize = sizeof(s128);
  1343. X    lr.delim = (char *)0;
  1344. X    lr.echo = 0;
  1345. X    lgets_timeout(&lr);
  1346. X    value2 = DCE_get_sreg_value(regnum);
  1347. X    if(value2 < 0)
  1348. X        pprintf("PROBLEM setting modem S%d=%d; cannot talk to modem\n",
  1349. X                regnum,value);
  1350. X    else if(value != value2)
  1351. X        pprintf("PROBLEM setting modem S%d=%d; got %d back\n",
  1352. X                regnum,value,value2);
  1353. X    return((value != value2) ? -1 : 0);
  1354. X
  1355. X}    /* end of DCE_set_sreg */
  1356. X
  1357. X/*+-------------------------------------------------------------------------
  1358. X    DCE_autoanswer()
  1359. X--------------------------------------------------------------------------*/
  1360. Xvoid
  1361. XDCE_autoanswer()
  1362. X{
  1363. X    if(!Lmodem_autoans[0])
  1364. X        return;
  1365. X    nap(200L);
  1366. X    lputs_paced(20,"AT\r");
  1367. X    nap(100L);
  1368. X    lputs_paced(20,Lmodem_autoans); /* quiet modem */
  1369. X    lputs_paced(20,"\r");
  1370. X    nap(200L);
  1371. X    lputs_paced(20,Lmodem_autoans); /* quiet modem */
  1372. X    lputs_paced(20,"\r");
  1373. X    nap(200L);
  1374. X    lflush(0);
  1375. X}    /* end of DCE_autoanswer */
  1376. X
  1377. X/* end of ecuDCE.c */
  1378. X/* vi: set tabstop=4 shiftwidth=4: */
  1379. SHAR_EOF
  1380. $TOUCH -am 1224222790 'ecuDCE.c' &&
  1381. chmod 0644 ecuDCE.c ||
  1382. echo 'restore of ecuDCE.c failed'
  1383. Wc_c="`wc -c < 'ecuDCE.c'`"
  1384. test 20605 -eq "$Wc_c" ||
  1385.     echo 'ecuDCE.c: original size 20605, current size' "$Wc_c"
  1386. # ============= ecuLCK.c ==============
  1387. echo 'x - extracting ecuLCK.c (Text)'
  1388. sed 's/^X//' << 'SHAR_EOF' > 'ecuLCK.c' &&
  1389. X#define HONEYDANBER /* means use ASCII pids in lock files */
  1390. X#if defined(SHARE_DEBUG)
  1391. X#define LOG_LOCKS
  1392. X#endif
  1393. X/*+-----------------------------------------------------------------------
  1394. X    ecuLCK.c -- ECU lock file management
  1395. X    wht@n4hgf.Mt-Park.GA.US
  1396. X
  1397. X  Defined functions:
  1398. X    is_active_lock(name)
  1399. X    line_locked(ttyname)
  1400. X    make_lock_name(ttyname,lock_file_name)
  1401. X
  1402. XLock files under XENIX are supposed to use the direct line name
  1403. X(lower-case last letter); we create only the lower-case case, but
  1404. Xcheck for both.
  1405. X------------------------------------------------------------------------*/
  1406. X/*+:EDITS:*/
  1407. X/*:11-19-1990-01:05-wht@n4hgf-remove lock in is_active_lock if we locked */
  1408. X/*:10-16-1990-20:43-wht@n4hgf-add SHARE_DEBUG */
  1409. X/*:09-19-1990-19:36-wht@n4hgf-ecu_log_event now gets pid for log from caller */
  1410. X/*:08-14-1990-20:39-wht@n4hgf-ecu3.00-flush old edit history */
  1411. X
  1412. X#include "ecu.h"
  1413. X#include "utmpstatus.h"
  1414. X
  1415. Xextern int errno;
  1416. Xextern char ungetty_ttyname[];
  1417. X
  1418. X/*+-------------------------------------------------------------------------
  1419. X    make_lock_name(ttyname,lock_file_name)
  1420. X--------------------------------------------------------------------------*/
  1421. Xmake_lock_name(ttyname,lock_file_name)
  1422. Xchar *ttyname;
  1423. Xchar *lock_file_name;
  1424. X{
  1425. X
  1426. X    if((ulindex(ttyname,"/dev/tty")) != 0)
  1427. X        return(LOPEN_INVALID);
  1428. X
  1429. X    strcpy(lock_file_name,"/usr/spool/uucp/LCK..");
  1430. X    strcat(lock_file_name,ttyname + 5);
  1431. X    return(0);
  1432. X
  1433. X}    /* end of make_lock_name */
  1434. X
  1435. X/*+-------------------------------------------------------------------------
  1436. X    is_active_lock(name) - check to see if lock still active
  1437. X
  1438. Xif not unlink any old lock name
  1439. X--------------------------------------------------------------------------*/
  1440. Xis_active_lock(name)
  1441. Xregister char *name;
  1442. X{
  1443. Xregister itmp;
  1444. Xint lockpid;
  1445. Xint fd;
  1446. Xint status = 0;
  1447. Xchar pidstr[12];
  1448. X
  1449. X    errno = 0;
  1450. X    if((fd = open(name,O_RDONLY,0)) < 0)
  1451. X    {
  1452. X        if(errno != ENOENT)
  1453. X            status = LOPEN_LCKERR;
  1454. X        goto RETURN_STATUS;
  1455. X    }
  1456. X
  1457. X#if defined(HONEYDANBER)
  1458. X    itmp = read(fd,(char *)pidstr,11);
  1459. X    pidstr[11] = 0;
  1460. X    close(fd);
  1461. X    if(itmp != 11)
  1462. X        goto UNLINK_OLD_LOCK;
  1463. X    lockpid = atoi(pidstr);
  1464. X#else
  1465. X    itmp = read(fd,(char *)&lockpid,sizeof(int));
  1466. X    close(fd);
  1467. X    if(itmp != sizeof(int))
  1468. X        goto UNLINK_OLD_LOCK;
  1469. X#endif
  1470. X
  1471. X/*
  1472. X * during certain error recovery conditions,
  1473. X * we could get hurt by our own lock file
  1474. X */
  1475. X    if(lockpid == getpid())        /* if we are the locker, kill it */
  1476. X        goto UNLINK_OLD_LOCK;
  1477. X
  1478. X    if((!(itmp = kill(lockpid,0))) || (errno != ESRCH))
  1479. X    {
  1480. X        errno = EACCES;        /* for hangup() */
  1481. X        status = lockpid;
  1482. X        goto RETURN_STATUS;
  1483. X    }
  1484. X
  1485. XUNLINK_OLD_LOCK:
  1486. X    if(unlink(name))
  1487. X        status = LOPEN_LCKERR;
  1488. X
  1489. XRETURN_STATUS:
  1490. X
  1491. X#if defined(LOG_LOCKS)
  1492. X{ char s128[128];
  1493. X  extern char *errno_text();
  1494. X    sprintf(s128,"ISLOCK %s status=%d errno=%s",
  1495. X        name,status,errno_text(errno));
  1496. X    ecu_log_event(getpid(),s128);
  1497. X}
  1498. X#endif
  1499. X
  1500. X    return(status);
  1501. X}    /* end of is_active_lock */
  1502. X
  1503. X/*+-----------------------------------------------------------------------
  1504. X    line_locked(ttyname) - boolean test for locked line
  1505. X
  1506. X  ttyname must be of style "/dev/ttyxx"
  1507. X  Returns locking pid if locked else LOPEN lock error code (< 0) else 0
  1508. X  Either modem or direct name might be locked, so check both
  1509. X------------------------------------------------------------------------*/
  1510. Xint
  1511. Xline_locked(ttyname)
  1512. Xchar *ttyname;
  1513. X{
  1514. Xregister itmp;
  1515. Xchar lock_file_name[64];
  1516. X    
  1517. X    make_lock_name(ttyname,lock_file_name);
  1518. X    if(itmp = is_active_lock(lock_file_name))
  1519. X        return(itmp);
  1520. X
  1521. X#if defined(M_XENIX) || defined(M_UNIX)
  1522. X    if(isalpha(lock_file_name[itmp = strlen(lock_file_name) - 1]))
  1523. X    {
  1524. X        lock_file_name[itmp] ^= 0x20;    /* lower->upper, upper->lower */
  1525. X        if(itmp = is_active_lock(lock_file_name))
  1526. X            return(itmp);
  1527. X    }
  1528. X#endif
  1529. X    return(0);
  1530. X
  1531. X}    /* end of line_locked */
  1532. X
  1533. X/* end of ecuLCK.c */
  1534. X/* vi: set tabstop=4 shiftwidth=4: */
  1535. SHAR_EOF
  1536. $TOUCH -am 1224222790 'ecuLCK.c' &&
  1537. chmod 0644 ecuLCK.c ||
  1538. echo 'restore of ecuLCK.c failed'
  1539. Wc_c="`wc -c < 'ecuLCK.c'`"
  1540. test 3727 -eq "$Wc_c" ||
  1541.     echo 'ecuLCK.c: original size 3727, current size' "$Wc_c"
  1542. # ============= ecuchdir.c ==============
  1543. echo 'x - extracting ecuchdir.c (Text)'
  1544. sed 's/^X//' << 'SHAR_EOF' > 'ecuchdir.c' &&
  1545. X/*+-------------------------------------------------------------------------
  1546. X    ecuchdir.c - ECU change directory command/history
  1547. X    wht@n4hgf.Mt-Park.GA.US
  1548. X
  1549. X  Defined functions:
  1550. X    cd_array_delete(arg,narg)
  1551. X    cd_array_delete_usage()
  1552. X    cd_array_init()
  1553. X    cd_array_read(arg,narg)
  1554. X    cd_array_save(arg,narg)
  1555. X    change_directory(cdarg,arg_present_flag)
  1556. X    expand_dirname(dirname)
  1557. X
  1558. X--------------------------------------------------------------------------*/
  1559. X/*+:EDITS:*/
  1560. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1561. X
  1562. X#include "ecu.h"
  1563. X#include "ecukey.h"
  1564. X#include <pwd.h>
  1565. X
  1566. X#define CD_QUAN        44
  1567. X#define CD_PATHLEN    130
  1568. Xchar *cd_array[CD_QUAN];
  1569. Xuint cd_in_use = 0;
  1570. X
  1571. Xextern char curr_dir[];        /* current working directory */
  1572. Xextern char errmsg[];
  1573. Xextern int errno;
  1574. X
  1575. X/*+-------------------------------------------------------------------------
  1576. X    cd_array_read(arg,narg)
  1577. X--------------------------------------------------------------------------*/
  1578. Xvoid
  1579. Xcd_array_read(arg,narg)
  1580. Xchar **arg;
  1581. Xint narg;
  1582. X{
  1583. Xchar dirpath[CD_PATHLEN];
  1584. XFILE *fpcd;
  1585. XFILE *fopen();
  1586. Xregister char *cptr;
  1587. Xchar *skip_ld_break();
  1588. X
  1589. X    get_home_dir(dirpath);
  1590. X    strcat(dirpath,"/.ecu/dir");
  1591. X    if((fpcd = fopen(dirpath,"r")) == (FILE *)0)
  1592. X        return;        /* none found */
  1593. X
  1594. X    for(cd_in_use = 0; cd_in_use < CD_QUAN; cd_in_use++)
  1595. X    {
  1596. X        if(fgets(dirpath,sizeof(dirpath),fpcd) == (char *)0)
  1597. X            break;
  1598. X        dirpath[strlen(dirpath) - 1] = 0;
  1599. X        cptr = skip_ld_break(dirpath);
  1600. X        if(strlen(cptr) == 0)
  1601. X        {
  1602. X            --cd_in_use;
  1603. X            continue;
  1604. X        }
  1605. X        strcpy(cd_array[cd_in_use],cptr);
  1606. X    }
  1607. X    fclose(fpcd);
  1608. X}    /* end of cd_array_read */
  1609. X
  1610. X/*+-------------------------------------------------------------------------
  1611. X    cd_array_save(arg,narg)
  1612. X--------------------------------------------------------------------------*/
  1613. Xvoid cd_array_save(arg,narg)
  1614. Xchar **arg;
  1615. Xint narg;
  1616. X{
  1617. Xregister icd;
  1618. Xchar savepath[256];
  1619. XFILE *fpcd;
  1620. XFILE *fopen();
  1621. X
  1622. X    get_home_dir(savepath);
  1623. X    strcat(savepath,"/.ecu/dir");
  1624. X
  1625. X    if(cd_in_use == 0)
  1626. X    {
  1627. X        ff(se,"No directory list to save in %s\r\n",savepath);
  1628. X        return;
  1629. X    }
  1630. X    if((fpcd = fopen(savepath,"w")) == (FILE *)0)
  1631. X    {
  1632. X        ff(se,"%s could not be opened\r\n",savepath);
  1633. X        return;
  1634. X    }
  1635. X
  1636. X    for(icd = 0; icd < cd_in_use; icd++)
  1637. X        fprintf(fpcd,"%s\n",cd_array[icd]);
  1638. X    fclose(fpcd);
  1639. X    ff(se,"%d entries saved in %s\r\n",cd_in_use,savepath);
  1640. X
  1641. X}    /* end of cd_array_save */
  1642. X
  1643. X/*+-------------------------------------------------------------------------
  1644. X    cd_array_delete_usage()
  1645. X--------------------------------------------------------------------------*/
  1646. Xvoid
  1647. Xcd_array_delete_usage()
  1648. X{
  1649. X    ff(se,"usage: d[elete] <1st> [<last>]\r\n");
  1650. X}    /* end of cd_array_delete_usage */
  1651. X
  1652. X/*+-------------------------------------------------------------------------
  1653. X    cd_array_delete(arg,narg)
  1654. X--------------------------------------------------------------------------*/
  1655. Xcd_array_delete(arg,narg)
  1656. Xchar **arg;
  1657. Xint narg;
  1658. X{
  1659. Xuint first;        /* 1st to delete */
  1660. Xuint last;        /* last to delete */
  1661. X
  1662. X    if((narg < 2) || (narg > 3))
  1663. X    {
  1664. X        cd_array_delete_usage();
  1665. X        return(-1);
  1666. X    }
  1667. X
  1668. X    first = atoi(arg[1]) - 1;
  1669. X    if(narg == 2)
  1670. X        last = first;
  1671. X    else
  1672. X        last = atoi(arg[2]) - 1;
  1673. X
  1674. X    if((first > (cd_in_use - 1)) || (last > (cd_in_use - 1)) || (last < first))
  1675. X    {
  1676. X        cd_array_delete_usage();
  1677. X        return(-1);
  1678. X    }
  1679. X
  1680. X    if(last == (cd_in_use - 1))
  1681. X    {
  1682. X        cd_in_use = first;
  1683. X    }
  1684. X    else
  1685. X    {
  1686. X    int count_less = last - first + 1;
  1687. X        last++;
  1688. X        while(last != cd_in_use)
  1689. X            strcpy(cd_array[first++],cd_array[last++]);
  1690. X        cd_in_use -= count_less;
  1691. X    }
  1692. X    return(0);
  1693. X}    /* end of cd_array_delete */
  1694. X
  1695. X/*+-------------------------------------------------------------------------
  1696. X    cd_array_init()
  1697. X--------------------------------------------------------------------------*/
  1698. Xvoid
  1699. Xcd_array_init()
  1700. X{
  1701. Xregister itmp;
  1702. X
  1703. X/*allocate change_directory stack */
  1704. X    for(itmp = 0; itmp < CD_QUAN; itmp++)
  1705. X    {
  1706. X        if(!(cd_array[itmp] = malloc(CD_PATHLEN + 1)))
  1707. X        {
  1708. X            ff(se,"Not enough memory for cd stack\r\n");
  1709. X            exit(1);
  1710. X        }
  1711. X        *cd_array[itmp] = 0;
  1712. X    }
  1713. X    (void)cd_array_read(cd_array,0);
  1714. X}    /* end of cd_array_init */
  1715. X
  1716. X/*+-------------------------------------------------------------------------
  1717. X    expand_dirname(dirname,maxlen) - convert dirnames with shell chars
  1718. X--------------------------------------------------------------------------*/
  1719. Xexpand_dirname(dirname,maxlen)
  1720. Xchar *dirname;
  1721. Xint maxlen;
  1722. X{
  1723. Xchar s256[256];
  1724. Xchar *expcmd;
  1725. X
  1726. X    if(!find_shell_chars(dirname))
  1727. X        return(0);
  1728. X
  1729. X    sprintf(s256,"`ls -d %s`",dirname);
  1730. X    if(expand_cmd_with_wildlist(s256,&expcmd))
  1731. X    {
  1732. X        strcpy(errmsg,"No files match");
  1733. X        return(-1);
  1734. X    }
  1735. X    strncpy(dirname,expcmd,maxlen);
  1736. X    dirname[maxlen - 1] = 0;
  1737. X    free(expcmd);
  1738. X    if(strchr(dirname,' '))
  1739. X    {
  1740. X        strcpy(errmsg,"Too many files");
  1741. X        return(-1);
  1742. X    }
  1743. X    return(0);
  1744. X
  1745. X}    /* end of expand_dirname */
  1746. X
  1747. X/*+-------------------------------------------------------------------------
  1748. X    change_directory(dirname,arg_present_flag)
  1749. X
  1750. X  Change directory to 'dirname' if arg_present_flag is true,
  1751. X  else if flag 0, ask for new directory name and change to it
  1752. X  This procedure maintains the global variable 'curr_dir' that
  1753. X  reflects the ecu transmitter and receiver process current
  1754. X  working directory.
  1755. X--------------------------------------------------------------------------*/
  1756. Xchange_directory(cdarg,arg_present_flag)
  1757. Xchar *cdarg;
  1758. Xint arg_present_flag;
  1759. X{
  1760. Xregister icd;
  1761. Xregister itmp;
  1762. Xchar s130[130];
  1763. X#define BLD_ARG_MAX    5
  1764. Xchar *arg[BLD_ARG_MAX];
  1765. Xint narg;
  1766. Xint longest;
  1767. X
  1768. X    if(cd_in_use == 0)
  1769. X        cd_array_read(arg,0);
  1770. X
  1771. X    fputs("  ",se);
  1772. X
  1773. X    if(arg_present_flag)        /* if there is an argument ... */
  1774. X    {
  1775. X        if(isdigit(*cdarg))        /* ... and first char is digit */
  1776. X        {
  1777. X            icd = atoi(cdarg) - 1;
  1778. X            if(icd >= cd_in_use)
  1779. X                goto DISPLAY_CD_ARRAY;
  1780. X            strncpy(s130,cd_array[icd],sizeof(s130) - 1);
  1781. X        }
  1782. X        else
  1783. X            strncpy(s130,cdarg,sizeof(s130) - 1);    /* literal dir spec */
  1784. X
  1785. X        s130[sizeof(s130) - 1] = 0;
  1786. X    }
  1787. X    else        /* no arg to cd command */
  1788. X    {
  1789. XDISPLAY_CD_ARRAY:
  1790. X        fputs("\r\n",se);
  1791. X        longest = 0;
  1792. X        for(icd = 0; icd < CD_QUAN/2; icd++)
  1793. X        {
  1794. X            if(icd >= cd_in_use)
  1795. X                break;
  1796. X            if(longest < (itmp = strlen(cd_array[icd])))
  1797. X                longest = itmp;
  1798. X        }
  1799. X        longest += 4;
  1800. X        if(longest < 36)
  1801. X            longest += 4;
  1802. X        for(icd = 0; icd < CD_QUAN/2; icd++)
  1803. X        {
  1804. X            if(icd >= cd_in_use)
  1805. X                break;
  1806. X            sprintf(s130,"%2d %s ",icd + 1,cd_array[icd]);
  1807. X            fputs(s130,se);
  1808. X            if(icd + CD_QUAN/2 >= cd_in_use)
  1809. X                fputs("\r\n",se);
  1810. X            else
  1811. X            {
  1812. X                itmp = longest - strlen(s130);
  1813. X                while(itmp-- > 0)
  1814. X                    fputc(' ',se);
  1815. X                sprintf(s130,"%2d %s\r\n",
  1816. X                    icd + 1 + CD_QUAN/2,cd_array[icd + CD_QUAN/2]);
  1817. X                fputs(s130,se);
  1818. X            
  1819. X            }
  1820. X        }
  1821. X        fputs("current dir: ",se);
  1822. X        tcap_stand_out();
  1823. X        ff(se," %s ",curr_dir);
  1824. X        tcap_stand_end();
  1825. X        tcap_eeol();
  1826. X        fputs("\r\n",se);
  1827. X
  1828. XGET_NEW_DIR:
  1829. X        fputs("New dir, <#>, %save, %read, %del, %xmitcd, <enter>:  ",se);
  1830. X        ttygets(s130,sizeof(s130),1);
  1831. X        if( (s130[0] == ESC) || (strlen(s130) == 0) )
  1832. X        {
  1833. X            ff(se,"no directory change\r\n");
  1834. X            return(0);
  1835. X        }
  1836. X        else if(s130[0] == '%')
  1837. X        {
  1838. X            build_str_array(s130,arg,BLD_ARG_MAX,&narg);
  1839. X
  1840. X            if(minunique("save",&s130[1],1))
  1841. X            {
  1842. X                cd_array_save(arg,narg);
  1843. X                goto GET_NEW_DIR;
  1844. X            }
  1845. X            else if(minunique("read",&s130[1],1))
  1846. X            {
  1847. X                cd_array_read(arg,narg);
  1848. X                goto DISPLAY_CD_ARRAY;
  1849. X            }
  1850. X            else if(minunique("delete",&s130[1],1))
  1851. X            {
  1852. X                if(cd_array_delete(arg,narg))
  1853. X                    goto GET_NEW_DIR;
  1854. X                else
  1855. X                    goto DISPLAY_CD_ARRAY;
  1856. X            }
  1857. X            else if(minunique("xmitcd",&s130[1],1))
  1858. X            {
  1859. X                lputs("cd ");
  1860. X                lputs(curr_dir);
  1861. X                lputc('\r');
  1862. X                return(0);
  1863. X            }
  1864. X            else
  1865. X            {
  1866. X                ff(se,"Invalid cd subcommand\r\n");
  1867. X                goto GET_NEW_DIR;
  1868. X            }
  1869. X        }
  1870. X        else if(icd = atoi(s130))
  1871. X        {
  1872. X            icd--;
  1873. X            if(icd >= cd_in_use)
  1874. X                goto GET_NEW_DIR;
  1875. X            strncpy(s130,cd_array[icd],sizeof(s130) - 1);
  1876. X            s130[sizeof(s130) - 1] = 0;
  1877. X        }
  1878. X    }
  1879. X    if(expand_dirname(s130,sizeof(s130)))
  1880. X    {
  1881. X        ff(se,"%s\r\n",errmsg);
  1882. X        return(-1);
  1883. X    }
  1884. X    if(chdir(s130) < 0)        /* now change to the new directory */
  1885. X    {
  1886. X        perror(s130);        /* print error if we get one */
  1887. X        ff(se,"\r\n");
  1888. X        return(-1);
  1889. X    }
  1890. X    get_curr_dir(curr_dir,256);
  1891. X
  1892. X    fputs("\r\nconfirmed: ",se);
  1893. X    tcap_stand_out();
  1894. X    ff(se," %s ",curr_dir);
  1895. X    tcap_stand_end();
  1896. X    fputs("\r\n",se);
  1897. X    fflush(se);
  1898. X
  1899. X    for(icd = 0; icd < cd_in_use; icd++)
  1900. X    {
  1901. X        if(strcmp(curr_dir,cd_array[icd]) == 0)
  1902. X            return(0);
  1903. X    }
  1904. X    if(cd_in_use == CD_QUAN)
  1905. X    {
  1906. X        for(icd = 1; icd < CD_QUAN; icd++)
  1907. X        {
  1908. X            strcpy(cd_array[icd - 1],cd_array[icd]);
  1909. X        }
  1910. X        strcpy(cd_array[CD_QUAN - 1],curr_dir);
  1911. X    }
  1912. X    else
  1913. X        strcpy(cd_array[cd_in_use++],curr_dir);
  1914. X
  1915. X    return(0);
  1916. X
  1917. X}    /* end of change_directory */
  1918. X/* end of ecuchdir.c */
  1919. X/* vi: set tabstop=4 shiftwidth=4: */
  1920. SHAR_EOF
  1921. $TOUCH -am 1224222790 'ecuchdir.c' &&
  1922. chmod 0644 ecuchdir.c ||
  1923. echo 'restore of ecuchdir.c failed'
  1924. Wc_c="`wc -c < 'ecuchdir.c'`"
  1925. test 8377 -eq "$Wc_c" ||
  1926.     echo 'ecuchdir.c: original size 8377, current size' "$Wc_c"
  1927. # ============= ecudump.c ==============
  1928. echo 'x - extracting ecudump.c (Text)'
  1929. sed 's/^X//' << 'SHAR_EOF' > 'ecudump.c' &&
  1930. X/*+-----------------------------------------------------------------------
  1931. X    ecudump.c  -- very generic hex/graphics dump development aid
  1932. X    wht@n4hgf.Mt-Park.GA.US
  1933. X
  1934. X  Defined functions:
  1935. X    dump_putc(ch)
  1936. X    dump_puts(str)
  1937. X    hex_dump(str,len,title,terse_flag)
  1938. X    hex_dump_fp(fp,str,len,title,terse_flag)
  1939. X    hex_dump16(int16)
  1940. X    hex_dump32(int32)
  1941. X    hex_dump4(int4)
  1942. X    hex_dump8(int8)
  1943. X
  1944. X------------------------------------------------------------------------*/
  1945. X/*+:EDITS:*/
  1946. X/*:08-14-1990-20:40-wht@n4hgf-ecu3.00-flush old edit history */
  1947. X
  1948. X#include "ecu.h"
  1949. X
  1950. Xstatic FILE *dumpfp;
  1951. X
  1952. X/*+-------------------------------------------------------------------------
  1953. X    dump_putc(ch)
  1954. X--------------------------------------------------------------------------*/
  1955. Xvoid
  1956. Xdump_putc(ch)
  1957. Xchar ch;
  1958. X{
  1959. X    if(dumpfp == se)
  1960. X        pputc(ch);
  1961. X    else
  1962. X        fputc(ch,dumpfp);
  1963. X}    /* end of dump_putc */
  1964. X
  1965. X
  1966. X/*+-------------------------------------------------------------------------
  1967. X    dump_puts(str)
  1968. X--------------------------------------------------------------------------*/
  1969. Xvoid
  1970. Xdump_puts(str)
  1971. Xchar *str;
  1972. X{
  1973. X    if(dumpfp == se)
  1974. X        pputs(str);
  1975. X    else
  1976. X        fputs(str,dumpfp);
  1977. X}    /* end of dump_puts */
  1978. X
  1979. X
  1980. X/*+-----------------------------------------------------------------------
  1981. X    hex_dump#... subservient routines
  1982. X------------------------------------------------------------------------*/
  1983. Xvoid hex_dump4(int4)
  1984. Xuchar int4;
  1985. X{
  1986. X    int4 &= 15;
  1987. X    dump_putc((int4 >= 10) ? (int4 + 'A' - 10) : (int4 + '0'));
  1988. X}
  1989. X
  1990. Xvoid hex_dump8(int8)
  1991. Xuchar int8;
  1992. X{
  1993. X    hex_dump4(int8 >> 4);
  1994. X    hex_dump4(int8);
  1995. X}
  1996. X
  1997. Xvoid hex_dump16(int16)
  1998. Xushort int16;
  1999. X{
  2000. X    hex_dump8(int16 >> 8);
  2001. X    hex_dump8(int16);
  2002. X}
  2003. X
  2004. Xvoid hex_dump32(int32)
  2005. Xulong int32;
  2006. X{
  2007. X    hex_dump16(int32 >> 16);
  2008. X    hex_dump16(int32);
  2009. X}
  2010. X
  2011. X
  2012. X/*+-----------------------------------------------------------------
  2013. X    hex_dump_fp(fp,str,len,title,terse_flag)
  2014. X
  2015. X  if 'title' not NULL, title is printed... 'terse_flag'
  2016. X  controls whether or not the title is "conspicuous" with
  2017. X  hyphens before and after it making title line >70 chars long
  2018. X------------------------------------------------------------------*/
  2019. Xvoid
  2020. Xhex_dump_fp(fp,str,len,title,terse_flag)
  2021. XFILE *fp;
  2022. Xchar *str;
  2023. Xint len;
  2024. Xchar *title;
  2025. Xint terse_flag;
  2026. X{
  2027. Xint istr;
  2028. Xregister ipos;
  2029. Xregister itmp;
  2030. X
  2031. X    dumpfp = fp;
  2032. X
  2033. X    if(title && (istr = strlen(title)))
  2034. X    {
  2035. X        if(!terse_flag)
  2036. X        {
  2037. X            ipos = (73 - istr) / 2;
  2038. X            itmp = ipos;
  2039. X            while(itmp--)
  2040. X                dump_putc('-');
  2041. X            dump_putc(' ');
  2042. X            if(istr & 1)
  2043. X                ipos--;
  2044. X        }
  2045. X        dump_puts(title);
  2046. X        if(!terse_flag)
  2047. X        {
  2048. X            dump_putc(' ');
  2049. X            while(ipos--)
  2050. X                dump_putc('-');
  2051. X        }
  2052. X        if(dumpfp == se)
  2053. X            dump_puts("\r\n");
  2054. X        else
  2055. X            dump_puts("\n");
  2056. X
  2057. X    }
  2058. X
  2059. X    istr = 0;
  2060. X    while(istr < len)
  2061. X    {
  2062. X        hex_dump16(istr);
  2063. X        dump_putc(' ');
  2064. X        for(itmp = 0; itmp < 16; ++itmp)
  2065. X        {
  2066. X            ipos = istr + itmp;
  2067. X            if(ipos >= len)
  2068. X            {
  2069. X                if(!terse_flag)
  2070. X                    dump_puts("   ");
  2071. X                continue;
  2072. X            }
  2073. X            dump_putc(' ');
  2074. X            hex_dump8(str[ipos]);
  2075. X        }
  2076. X        dump_puts(" | ");
  2077. X        for(itmp = 0; itmp < 16; ++itmp)
  2078. X        {
  2079. X            ipos = istr + itmp;
  2080. X            if( (ipos) >= len)
  2081. X            {
  2082. X                if(!terse_flag)
  2083. X                    dump_putc(' ');
  2084. X            }
  2085. X            else
  2086. X            {
  2087. X                dump_putc((str[ipos] >= ' ' && str[ipos] < 0x7f)
  2088. X                     ? str[ipos] : '.' );
  2089. X            }
  2090. X        }
  2091. X        if(dumpfp == se)
  2092. X            dump_puts(" |\r\n");
  2093. X        else
  2094. X            dump_puts(" |\n");
  2095. X        istr += 16;
  2096. X    }   /* end of while(istr < len) */
  2097. X
  2098. X}    /* end of hex_dump_fp */
  2099. X
  2100. X/*+-------------------------------------------------------------------------
  2101. X    hex_dump(str,len,title,terse_flag)
  2102. X--------------------------------------------------------------------------*/
  2103. Xvoid
  2104. Xhex_dump(str,len,title,terse_flag)
  2105. Xchar *str;
  2106. Xint len;
  2107. Xchar *title;
  2108. Xint terse_flag;
  2109. X{
  2110. X    hex_dump_fp(se,str,len,title,terse_flag);
  2111. X}    /* end of hex_dump_fp */
  2112. X/* end of ecudump.c */
  2113. X/* vi: set tabstop=4 shiftwidth=4: */
  2114. SHAR_EOF
  2115. $TOUCH -am 1224222890 'ecudump.c' &&
  2116. chmod 0644 ecudump.c ||
  2117. echo 'restore of ecudump.c failed'
  2118. Wc_c="`wc -c < 'ecudump.c'`"
  2119. test 3656 -eq "$Wc_c" ||
  2120.     echo 'ecudump.c: original size 3656, current size' "$Wc_c"
  2121. true || echo 'restore of ecufinsert.c failed'
  2122. echo End of part 2, continue with part 3
  2123. exit 0
  2124. --------------------------------------------------------------------
  2125. Warren Tucker, TuckerWare emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  2126. Hacker Extraordinaire  d' async PADs,  pods,  proteins and protocols
  2127.  
  2128. exit 0 # Just in case...
  2129. -- 
  2130. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2131. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2132. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2133. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2134.